package com.itheima.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.Clazz;
import com.itheima.entity.EmpQueryParam;
import com.itheima.entity.PageBean;
import com.itheima.entity.Student;
import com.itheima.mapper.ClazzMapper;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class) //开启事务

public class ClazzServiceImpl implements ClazzService {

    @Autowired
    private ClazzMapper clazzMapper;

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Override
    public PageBean page(EmpQueryParam param) {

        //1.设置分页参数
        PageHelper.startPage(param.getPage(),param.getPageSize());

        //2.调用mapper的列表查询方法
        List<Clazz> clazzes = clazzMapper.list(param);
        Page p=(Page) clazzes;

        //3.封装到PageBean对象并返回
        return new PageBean(p.getTotal(),clazzes);


    }
}
